package com.app.utils;

import java.util.regex.Pattern;

public class Judges {

    /**
     * 判断文件地址是否合理
     * @return true(合理)
     */
    public static boolean judgePath(String path){
        if (path==null)return false;
        path=path.replace("\\","/");
        // 开头是否标准，是否存在 ./
        if (path.matches("[0-9]*/.*")&&!path.matches(".*(\\./)+.*"))
            return !path.matches("^.*[:<>|\\*\\?]+.*$");//是否存在其它不允许字符
       return false;
    }
    public static boolean judgePaths(String ...paths){
        for (String path:paths)
            if (!judgePath(path))return false;
        return true;
    }
    /**
     * 判断共享秘钥是否合理
     * @return true(合理)
     */
    public static boolean judgeSharePw(String pw){
        if (pw==null)return false;
        return !Pattern.matches(".*[\\s\\n\\t]",pw);
    }
    /**
     * 判断共享是否合理
     * @return true(合理)
     */
    public static boolean judgePermission(String permission){
        if (permission==null)return false;
        return Pattern.matches("[01][01]-[01][01]-[01][01]",permission);
    }
}
